<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style type="text/css">
        .talk_con{
            width: 600px;
            height: 500px;
            border: 1px solid #666666;
            margin: 50px auto 0;
            background: #f9f9f9;
        }
        .talk_show{
            width: 580px;
            height: 420px;
            border: 1px solid #666666;
            margin: 10px auto 0;
            background: #ffffff;
            overflow: auto;
        }
        .talk_input{
            width: 580px;
            margin: 10px auto 0;
        }
        .whotalk{
            width: 80px;
            height: 30px;
            float: left;
            outline: none;
        }
        .talk_word{
            width: 420px;
            height: 26px;
            padding: 0px;
            float: left;
            margin-left: 10px;
            outline: none;
            text-indent: 10px;
        }
        .talk_sub{
            width: 56px;
            height: 30px;
            float: left;
            margin-left: 10px;
        }
        .atalk{
            margin: 10px;
        }
        .atalk span{
            display: inline-block;
            background: #0181cc;
            border-radius: 10px;
            color: #ffffff;
            padding: 5px 10px;
        }
        .btalk{
            margin: 10px;
            text-align: right;
        }
        .btalk span{
            display: inline-block;
            background: #ef8201;
            border-radius: 10px;
            color: #ffffff;
            padding: 5px 10px;
        }
    </style>
    <script src="../JS/jquery-1.12.4.min.js"></script>
    <script type="text/javascript">
        $(function () {
            var $word = $('#words'),
            $who = $('#who'),
            $talk = $('#talkword'),
            $btn = $('#talksub');
            $btn.click(function () {
                // // 读取属性值
                // var sVal01 = $who.prop('value');
                // var sVal02 = $talk.prop('value');

                // // 清空输入内容
                // $talk.prop({'value': ''})

                // 上述操作value属性方法可改用下方val()方法
                // 读
                var sVal01 = $who.val();
                var sVal02 = $talk.val();
                // 写
                $talk.val('');

                // 判断输入框是否为空
                if (sVal02 == '') {
                    alert('请输入内容');
                }

                var sTr = '';

                if (sVal01 == 0) {
                    sTr = '<div class="atalk"><span>A说：'+ sVal02 +'</span></div>';
                } else {
                    sTr = '<div class="btalk"><span>B说：'+ sVal02 +'</span></div>';
                }
                $word.html($word.html() + sTr);
            })
        })
    </script>
</head>
<body>
    <div class="talk_con">
        <div class="talk_show" id="words">
            <div class="atalk"><span>A说：wdnmd</span></div>
            <div class="btalk"><span>B说：wdnmd</span></div>
        </div>
        <div class="talk_input">
            <select name="" id="who" class="whotalk">
                <option value="0">A说：</option>
                <option value="1">B说：</option>
            </select>
            <input type="text" class="talk_word" id="talkword">
            <input type="button" value="发送" class="talk_sub" id="talksub">
        </div>
    </div>
</body>
</html>
